package com.baizan.daka.ui.adapter


import android.widget.ImageView
import android.widget.TextView
import com.baizan.daka.Constants
import com.baizan.daka.copyContent
import com.baizan.daka.mvp.model.bean.TaskInfoBean
import com.baizan.daka.openApp
import com.baizan.daka.showToast
import com.baizan.daka.ui.activity.ReceiveTaskActivity
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.dianzan.daka.R

class TaskingAdapter : BaseQuickAdapter<TaskInfoBean, BaseViewHolder>(R.layout.item_tasking) {


    override fun convert(helper: BaseViewHolder, item: TaskInfoBean) {
        helper.setText(R.id.user_phone_tv, "申请时间：${item?.overdueTime}")
            .setText(R.id.task_msg_tv, "要求：${item?.taskTypeName}")
            .setText(R.id.price_tv, "¥${item.taskPrice}")
            .setText(R.id.task_No_tv, "编号：${item.taskId}")
            .setText(R.id.copy_like_tv, "复制链接")
            .setText(R.id.open_video_tv, "打开视频")
        helper.getView<TextView>(R.id.copy_like_tv)
            .setOnClickListener {
                copyContent(mContext, item.videoUrl)
                showToast("复制成功")
            }
        helper.getView<TextView>(R.id.task_submit_tv)
            .setOnClickListener {
                ReceiveTaskActivity.start(mContext, item)
            }
        var taskLevel = helper.getView<TextView>(R.id.task_level_tv)
        when (item.taskClass) {
            1 -> {
                helper.getView<ImageView>(R.id.task_icon_iv)
                    .setImageResource(R.mipmap.icon_douyin)
                helper.getView<TextView>(R.id.open_video_tv)
                    .setOnClickListener {
                        copyContent(mContext, item.videoUrl)
                        openApp(mContext, Constants.DOUYIN_NAME).let {
                            if (!it) {
                                showToast("您没有安装抖音")
                            }
                        }
                    }
            }
            2 -> {
                helper.getView<ImageView>(R.id.task_icon_iv)
                    .setImageResource(R.mipmap.icon_kuanshou)
                helper.getView<TextView>(R.id.open_video_tv)
                    .setOnClickListener {
                        copyContent(mContext, item.videoUrl)
                        openApp(mContext, Constants.KUAISHOU_NAME).let {
                            if (!it) {
                                showToast("您没有安装快手")
                            }
                        }
                    }
            }
            0 -> {
                helper.getView<ImageView>(R.id.task_icon_iv)
                    .setImageResource(R.mipmap.icon_pengyouquan)
                helper.setText(R.id.copy_like_tv, "复制内容")
                    .setText(R.id.open_video_tv, "打开微信")
                helper.getView<TextView>(R.id.open_video_tv)
                    .setOnClickListener {
                        copyContent(mContext, item.videoUrl)
                        openApp(mContext, Constants.WEIXIN_NAME).let {
                            if (!it) {
                                showToast("您没有安装微信")
                            }
                        }
                    }
            }
        }

        when (item.taskLevel) {
            1 -> {
                taskLevel.text = "初级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_tasking_level_1)

            }
            2 -> {
                taskLevel.text = "中级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_tasking_level_2)

            }
            3 -> {
                taskLevel.text = "高级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_tasking_level_3)

            }
            4 -> {
                taskLevel.text = "至尊任务"
                taskLevel.setBackgroundResource(R.drawable.shape_tasking_level_3)

            }

        }
    }


}